<div v-cloak id="app" class="main-content">
    <one-table :option="option" :data="data" :loading="loading"  @current-change="handleCurrentChange" @size-change="handleSizeChange">
        <!-- 工具菜单 -->
        <template slot="menuLeft">
            <el-button type="primary" size="mini" @click="handleAdd">添加</el-button>
        </template>
        <!-- 自定义操作列 -->
        <template slot="operates" slot-scope="scope">
            <el-button size="mini" :disabled="scope.row.system" class="_tool" @click="handleEdit(scope.row, scope.index)">
                <i class="el-icon-edit"></i>
            </el-button>
            <el-popconfirm
                confirm-button-text="好的"
                cancel-button-text="不用了"
                icon="el-icon-info"
                icon-color="red"
                title="删除不能恢复,确定删除吗？"
                @confirm="handleDel(scope.row, scope.index)"
            >
            <el-button :disabled="scope.row.system" slot="reference" size="mini" class="_tool" type="danger">
                <i class="el-icon-delete"></i>
            </el-button>
            </el-popconfirm>
        </template>
    </one-table>
</div>
{include file="common@components/one-table"}
<script>
    new Vue({
        el: "#app",
        data() {
            return {
                loading: false,
                data: [],
                option: {
                    index: true,
                    header: true,
                    selection: false,
                    operates: {width:100},
                    page: {},
                    size: "mini",
                    column: [
                        {
                            label: "类型名称",
                            prop: "name"
                        },
                    ]
                }
            }
        },
        created() {
            this.getData()
        },
        methods: {
            // 获取数据
            getData() {
                let _this = this
                _this.loading = true
                request({
                    params: {
                        s: "tabbar/type/index",
                        page: _this.option.page.currentPage,
                        limit: _this.option.page.pageSize,
                    },
                    method: "post"
                }).then(e => {
                    _this.loading = false;
                    _this.data = e.data.data.list;
                    _this.option.page.total = e.data.data.count;
                })
            },
            //分页
            handleCurrentChange(currentPage) {
                let _this = this;
                _this.option.page.currentPage = currentPage;
                _this.getData();
            },
            //每页显示数
            handleSizeChange(val) {
                let _this = this;
                _this.option.page.pageSize = val;
                _this.getData();
            },
           
            //删除行
            handleDel (row, index) {
                let _this = this
                _this.loading = true
                request({
                    params: {
                        s: "tabbar/type/del/",
                		id:row.id,
                	},
                	method: "post"
                }).then(e => {
                    _this.data.splice(index, 1);
                	_this.loading = false;
                })
            },
            //添加
            handleAdd() {
                let _this = this
                navigateTo({
                    s: "tabbar/type/edit",
                })
            },
            //编辑
            handleEdit(row, index){
                let _this = this
                navigateTo({
                    s: "tabbar/type/edit",
                    id:row.id,
                })
            },
           
        }
    })
</script>